package com.xxwu.springgobang.component;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
@Component
public class OnlineUserManager {
    //游戏大厅
    private HashMap<Integer, WebSocketSession> gameHall = new HashMap<>();
    //游戏房间
    private HashMap<Integer, WebSocketSession> gameRoom = new HashMap<>();


    public void enterGameHall(Integer userId,WebSocketSession session) {
        //玩家进入上线，进入游戏大厅
        gameHall.put(userId, session);
    }

    public void exitGameHall(Integer userId) {
        gameHall.remove(userId);
    }

    public WebSocketSession getSessionFromGameHall(Integer userId) {
        return gameHall.get(userId);
    }

    public void enterGameRoom(Integer userId,WebSocketSession session) {
        gameRoom.put(userId, session);
    }
    public void exitGameRoom(Integer userId) {
        gameRoom.remove(userId);
    }
    public WebSocketSession getSessionFromGameRoom(Integer userId) {
        return gameRoom.get(userId);
    }
}
